package PTA;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
abstract class Shape implements Comparable<Shape>{
	final double PI = 3.14;
	public abstract double getPerimeter();
	public abstract double getArea();	
	@Override
	public int compareTo(Shape o) {
		if(this.getPerimeter()-o.getPerimeter()<0)
		    return -1;
		else if(this.getPerimeter()-o.getPerimeter()>0)
			return 1;
		else
			return 0;
	}
}
class Rectangle extends Shape{
	private int width;
	private int length;
	public Rectangle(int width,int length){
		this.width = width;
		this.length = length;
	}
	public String toString() {
		return "Rectangle [width=" + width + ", length=" + length + "]";
	}
	public double getPerimeter(){
		return (width+length)*2;		
	}
	public double getArea(){
		return width*length;
	}
}

class Circle extends Shape{
	private int radius;
	public Circle(int radius){
		this.radius = radius;
	}
	public String toString() {
		return "Circle [radius=" + radius + "]";
	}
	public double getPerimeter(){
		return 2*radius*PI;
	}
	public double getArea(){
		return PI*radius*radius;
	}
}

class PerComparator implements Comparator<Shape>{

	@Override
	public int compare(Shape o1, Shape o2) {
		if(o1.getPerimeter()-o2.getPerimeter()<0)
		    return -1;
		else if(o1.getPerimeter()-o2.getPerimeter()>0)
			return 1;
		else
			return 0;
	}
}

class AreaComparator implements Comparator<Shape>{
	@Override
	public int compare(Shape o1, Shape o2) {
		if(o1.getArea()-o2.getArea()<0)
			return -1;
		else if(o1.getArea()-o2.getArea()>0)
			return 1;
		else
			return 0;
	}
}

public class Main5 {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in );
		int n = in.nextInt();
		Shape[] shape = new Shape[n];
		for(int i=0;i<n;i++){
			String a = in.next();
			switch (a) {
			case "rect":
				in.nextLine();
				String a1 = in.nextLine();
				String[] a2 = a1.split(" ");
				int b = Integer.parseInt(a2[0]);
				int c = Integer.parseInt(a2[1]);
				Rectangle r = new Rectangle(b,c);
				shape[i] = r;break;
			case "cir":
				int d = in.nextInt();
				Circle C = new Circle(d);
				shape[i] = C;break;
			}
		}
		Arrays.sort(shape);
		for(int i=0;i<shape.length;i++){
			System.out.println(shape[i]);
		}
	}

}
